package org.coolsugar.annotation.annos;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class HiAspectAnno {
	@Pointcut("execution(* org.coolsugar.annotation.service.*.*(..))")
	public void mx(){
	}
	
	@Before("mx()")
	public void before(){
		System.out.println("before..");
	}
	
	@Around("mx()")
	public Object around(ProceedingJoinPoint pjp) throws Throwable{
		System.out.println("around before..");
		Object retObj = pjp.proceed();
		System.out.println("around after..");
		
		return retObj;
	}
	
	@AfterReturning(value="mx()",returning="retObj")
	public void afterReturning(JoinPoint jp,Object retObj){
		System.out.println("afterReturning.."+retObj);
	}
	
	//@AfterThrowing(value="execution(* org.coolsugar.annotation..service.*.*(..))",throwing="e")
	@AfterThrowing(value="mx()",throwing="e")
	public void afterThrowing(Throwable e){
		System.out.println("afterThrowing.."+e);
	}
	
	@After("mx()")
	public void after(){
		System.out.println("after..");
	}
}
